<!-- 首席服务员-工作动态-更多 -->
<template>
  <div class="container">
      <template v-if="!loading && list.length">
          <div class="item" v-for="(item, index) in list" @click="item.workType == 4 ? openDocument(item.filePath) : toDetail(item)" :key="index">
              <div class="title">{{item.title}}</div>
              <div class="time">{{item.publishTimeStr}}</div>
          </div>
      </template>
      <Empty v-if="!loading && !list.length"></Empty>
  </div>
</template>
<script>
import Empty from "../../../components/Empty.vue";
import { getChiefWorkSortAPI } from "../../../api/chief"
export default {
  components: { Empty },
  data() {
      return {
          loading: false,
          list: [],
          title: "",
          progressName: '工作进展',
          newsName: '新闻报道',
          briefName: '工作简报',
      };
  },
  onShareAppMessage() {},
  onLoad(options) {
    let { workType, title} = options;
    if (title) wx.setNavigationBarTitle({ title });
    this.loading = true;
    wx.showLoading({
        title: "加载中...",
    });
    getChiefWorkSortAPI({ workType: workType }).then((res) => {
        this.list = res.data;
        wx.hideLoading();
        this.loading = false;
    });
  },
  methods: {
    toDetail(item) {
      let typeName = '';  
      if (item.workType && item.workType == 1) {
        typeName = this.progressName;
      } else if (item.workType && item.workType == 2) {
        typeName = this.newsName;
      } else {
        typeName = this.briefName;
      }
      this.toPage("pages/chiefServer/work/detail", {
        id: item.id,
        title: typeName,
        publishTime: item.publishTimeStr,
        content: item.content,
        itemTitle: item.title,
      });
    },
    toPage(url, params) {
      this.$u.route({ url, params });
    },
    openDocument(url) {
      wx.showLoading({
          title: "打开文件中...",
      });
      wx.downloadFile({
          url,
          success: function (res) {
              const filePath = res.tempFilePath;
              wx.openDocument({
                  filePath: filePath,
                  success: function (res) {
                      wx.hideLoading();
                  },
              });
          },
      });
    },
  },
};
</script>
<style scoped lang="scss">
@import "../../../assets/scss/common.scss";

.container {
  min-height: 100vh;
  background-color: #fff;
  box-sizing: border-box;
  padding: 5px 15px;
  .item {
      border-bottom: 1px solid #efefef;
      padding: 10px 5px;
      &:last-child {
          border: none;
      }
      .title {
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 1;
          overflow: hidden;
          margin-bottom: 5px;
          color: #0c92ff;
      }
      .time {
          color: $color_secondary-text;
      }
  }
}
</style>
